﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Shop.Controllers;
using Shop.Mappers;
using Rhino.Mocks;
using Shop.Managers;
using System.Web;
using System.Security.Principal;
using System.Web.Mvc;

namespace TestsMyShop.Controller_Tests
{
    [TestFixture]
    public class Orders
    {
        [Test]
        public void Index_should_be_called_ManagerBasket_on_GetAllOrdersForUser()
        {
            IWebMapper mapper = MockRepository.GenerateMock<IWebMapper>();

            IManagerBasket managerBasket = MockRepository.GenerateMock<IManagerBasket>();
            //managerBasket.Stub(x => x.GetAllOrdersForUser("user", Entity.Baskets.State.NotOrdered)).IgnoreArguments()
            //    .Repeat.Once();

            managerBasket.Stub(x => x.GetAllOrdersForUser("test", Entity.Baskets.State.NotOrdered)).PropertyBehavior();

            IManagerProduct managerProduct = MockRepository.GenerateMock<IManagerProduct>();

            OrdersController controller = new OrdersController(managerBasket, managerProduct);
            controller.GetBasketJson();

            managerBasket.AssertWasCalled(x => x.GetAllOrdersForUser("user", Entity.Baskets.State.NotOrdered));
        }

        [Test]
        public void Test()
        {
            IManagerBasket managerBasket = MockRepository.GenerateMock<IManagerBasket>();
            IManagerProduct managerProduct = MockRepository.GenerateMock<IManagerProduct>();

            OrdersController controller = new OrdersController(managerBasket, managerProduct);

            var fakeHttpContextBase = MockRepository.GenerateMock<HttpContextBase>();
            fakeHttpContextBase.Stub(x => x.Request).Return(new FakeHttpRequestBase());

            var fakeControllerContext = MockRepository.GenerateMock<ControllerContext>();
            fakeControllerContext.Stub(x => x.HttpContext).Return(fakeHttpContextBase);

            controller.ControllerContext = fakeControllerContext;

            var resulrt = controller.Index();
           

        }
    }

    public class FakeHttpRequestBase : HttpRequestBase
    {
        public override bool IsAuthenticated
        {
            get
            {
                return false;
            }
        }
    }
}
